package ArrayAddSubtract;

import java.util.Scanner;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/
//数组的增删改查
public class ArrayAdd {
    public static void main(String[] args) {
        String[] names = {"Tom","Sam","Jack","Alice","Ruby","Robin",null};
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个名字：");
        String name = sc.next();
        int j = -1;
        for (int i = 0; i < names.length; i++) {
            if (names[i]==null) {//null  表示数组还有空位
                j = i;
                break;
            }
        }
        System.out.println("j="+j);
        if (j!=-1){
            names[j] = name;
        }
        else {
            System.out.println("数组已满，无法插入元素！");
        }
        System.out.println("打印名字:");
        for (String item : names) {
            System.out.print(item+"\t");
        }
    }
}
